using MediatR;
using Medical.Api.Read.Application.Command.Wms.WmsOutCauseCommand;
using Medical.Api.Read.Dto.WmsDto.WmsOutDto;
using Medical.ErrorCode;
using Medical.Api.Read.Service.WmsService;
using System.Threading;
using System.Threading.Tasks;

namespace Medical.Api.Read.Application.Handler.Wms.WmsOutCauseHandler
{
    /// <summary>
    /// 出库详情查询处理器，根据出库单id获取主表及明细
    /// </summary>
    public class GetOutCauseDetailByIdHandler : IRequestHandler<GetOutCauseDetailByIdCommand, ApiResult<WmsOutDetailReadDto>>
    {
        /// <summary>
        /// WMS服务
        /// </summary>
        private readonly IWmsService _service;
        /// <summary>
        /// 构造函数，注入WMS服务
        /// </summary>
        public GetOutCauseDetailByIdHandler(IWmsService service)
        {
            _service = service;
        }
        /// <summary>
        /// 查询出库详情及明细
        /// </summary>
        /// <param name="request">出库单id命令</param>
        /// <param name="cancellationToken"></param>
        /// <returns>出库详情及明细</returns>
        public async Task<ApiResult<WmsOutDetailReadDto>> Handle(GetOutCauseDetailByIdCommand request, CancellationToken cancellationToken)
        {
            return await _service.GetOutCauseDetailByIdAsync(request.Id);
        }
    }
}